<?php

class ExportarController extends Controller {

    /**
     * @var ExcelService
     */
    private $excelService;
    /**
     * @var PdfService
     */
    private $pdfService;

    public function __construct() {
        $this->excelService = ExcelService::getInstance();
        $this->pdfService = PdfService::getInstance();
    }

    public function excelRelatorioSetor() {
        $ArFilter = $this->getFilterDate();
        $Excel = $this->excelService->sectorReport($ArFilter);
        $this->save(SESSION_INTERFACE, 'ExcelReport', $Excel);
        $Excel->download();
        $this->view('excel_template', 'exportar', true);
    }

    public function excelRelatorioDepartamento() {
        $ArFilter = $this->getFilterDate();
        $Excel = $this->excelService->departamentReport($ArFilter);
        $this->save(SESSION_INTERFACE, 'ExcelReport', $Excel);
        $Excel->download();
        $this->view('excel_template', 'exportar', true);
    }

    public function excelRelatorioIndividual(){
        $ArFilter = $this->getFilterDate();
        $Excel = $this->excelService->individualReport($ArFilter);
        $this->save(SESSION_INTERFACE, 'ExcelReport', $Excel);
        $Excel->download();
        $this->view('excel_template', 'exportar', true);
    }

    public function excelRelatorioPessoal(){
        $ArFilter = $this->getFilterDate();
        $Excel = $this->excelService->personalReport($ArFilter);
        $this->save(SESSION_INTERFACE, 'ExcelReport', $Excel);
        $Excel->download();
        $this->view('excel_template', 'exportar', true);
    }

    public function excelRelatorioComunicado() {
        $StFilter = treatUrl('filter');
        $Excel = $this->excelService->annoncementReport($StFilter);
        $this->save(SESSION_INTERFACE, 'ExcelReport', $Excel);
        $Excel->download();
        $this->view('excel_template', 'exportar', true);
    }

    public function pdfRelatorioSetor() {
        $ArFilter = $this->getFilterDate();
        $Pdf = $this->pdfService->sectorReport($ArFilter);
        $Template = $this->getPdfTemplate();
        $Pdf->render($Template);
    }

    public function pdfRelatorioDepartamento(){
        $ArFilter = $this->getFilterDate();
        $Pdf = $this->pdfService->departamentReport($ArFilter);
        $Template = $this->getPdfTemplate();
        $Pdf->render($Template);
    }

    public function pdfRelatorioIndividual(){
        $ArFilter = $this->getFilterDate();
        $Pdf = $this->pdfService->individualReport($ArFilter);
        $Template = $this->getPdfTemplate();
        $Pdf->render($Template);
    }

    public function pdfRelatorioPessoal() {
        $ArFilter = $this->getFilterDate();
        $Pdf = $this->pdfService->personalReport($ArFilter);
        $Template = $this->getPdfTemplate();
        $Pdf->render($Template);
    }

    private function getPdfTemplate() {
        return file_get_contents(DRA_VIEW_PATH . 'package/exportar/pdf_template.view.phtml');
    }

    private function getFilterDate() {
        $ArFilter = json_decode( str_replace('-', '/', treatUrl('filter')), true );
        multipleEntities($ArFilter);
        return $ArFilter;
    }

}

?>


